package model;

import java.util.Calendar;
import java.util.Date;
import java.util.regex.Pattern;
import utils.ValidationUtils;

/**
 * Class User
 */
public class User {

    public static final String IMAGE_PATH = "D:\\Fred\\Cefet-MG\\Eng. Computação"
            + "\\PC2\\TP2\\src\\TP2\\build\\web\\user_images";
    
    //
    // Fields
    //
    
    /**
     * User login
     */
    private String login;
    /**
     * User password
     */
    private String password;
    /**
     * User name
     */
    private String name;
    /**
     * User email
     */
    private String email;
    /**
     * User birth date
     */
    private Date birthDate;

    //
    // Constructors
    //
    public User(String login, String password, String name, String email, Date birthDate)
            throws InvalidValueException {
        // Validates user login
        Pattern p = Pattern.compile("\\w+");
        if (!p.matcher(login).matches())
            throw new InvalidValueException("User login must be alphanumeric");
        this.login = login;
        
        setPassword(password);
        setName(name);
        setEmail(email);
        setBirthDate(birthDate);
    }

    //
    // Methods
    //
    
    //
    // Accessor methods
    //

    /**
     * Get the value of login
     * User login
     * @return the value of login
     */
    public String getLogin() {
        return login;
    }

    /**
     * Set the value of password
     * @param newVar the new value of password
     */
    public void setPassword(String newVar) {
        password = newVar;
    }

    /**
     * Get the value of password
     * @return the value of password
     */
    public String getPassword() {
        return password;
    }

    /**
     * Set the value of name
     * User name
     * @param newVar the new value of name
     */
    public void setName(String newVar) {
        name = newVar;
    }

    /**
     * Get the value of name
     * User name
     * @return the value of name
     */
    public String getName() {
        return name;
    }

    /**
     * Set the value of email
     * User email
     * @param newVar the new value of email
     */
    public void setEmail(String newVar) throws InvalidValueException {
        if (!ValidationUtils.isEmailValid(newVar))
            throw new InvalidValueException("Invalid email.");
        email = newVar;
    }

    /**
     * Get the value of email
     * User email
     * @return the value of email
     */
    public String getEmail() {
        return email;
    }

    /**
     * Set the value of birthDate
     * User birth date
     * @param newVar the new value of birthDate
     */
    public void setBirthDate(Date newVar) throws InvalidValueException {
        if (Calendar.getInstance().before(newVar))
            throw new InvalidValueException("The birth date must be earlier than current date.");
        birthDate = newVar;
    }

    /**
     * Get the value of birthDate
     * User birth date
     * @return the value of birthDate
     */
    public Date getBirthDate() {
        return birthDate;
    }
    
    //
    // Other methods
    //
    
}
